<template>
	<view class="sell">
		<view class="header">
			<view class="title">
				<view class="key">确认出售</view>
				<view class="close" @click="close">
					<image src="@/static/images/close.png"></image>
				</view>
			</view>
			<view class="desc">注意：上架小酒馆后无法退回酒柜，但是每售卖一瓶后隔日系统将在您的酒柜自动补充一瓶</view>
		</view>
		<scroll-view scroll-y class="scroll_view">
			<view class="list">
				<view class="item">
					<image :src="data_info.product.img"></image>
					<view class="item_view">
						<view class="name">{{data_info.product.name}}</view>
						<view class="oper">
							<view class="price">
								<view class="unit">￥</view>
								<view class="value">{{data_info.price}}</view>
							</view>
							<uv-number-box step="1" min="1" :max="data_info.stock" disabledInput integer v-model="value"
								@overlimit="overlimit"></uv-number-box>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="footer">
			<view class="number">
				<view class="key">数量：</view>
				<view class="value">{{value}}</view>
			</view>
			<view class="submit" @click="submit">出售</view>
		</view>
	</view>
</template>

<script setup>
	import {
		underwriteSell
	} from "@/request/api";
	import {
		ref
	} from "vue";

	const props = defineProps({
		item: Object
	});
	const data_info = props.item;

	const emit = defineEmits(["close"]);
	const value = ref(1);

	const overlimit = (type) => {
		if (type == "minus") {
			uni.$uv.toast("已经是最小值了");
		}
		if (type == "plus") {
			uni.$uv.toast("已经是最大值了");
		}
	};
	const close = () => emit('close');

	const submit = async () => {
		await underwriteSell({
			id: data_info.id,
			number: value.value
		});
		uni.$uv.toast("操作成功");
		emit('close');
	};
</script>

<style scoped lang="scss">
	.sell {
		.header {
			height: 175rpx;
			padding: 40rpx 30rpx 0rpx;
			box-sizing: border-box;

			.title {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.key {
					color: #111111;
					font-size: 36rpx;
					font-weight: bold;
				}

				.close {
					image {
						width: 32rpx;
						height: 32rpx;
					}
				}
			}

			.desc {
				line-height: 36rpx;
				color: #999999;
				font-size: 24rpx;
				padding: 20rpx 0;
				box-sizing: border-box;
			}
		}

		.scroll_view {
			border-top: 20rpx solid #EEEEEE;

			.list {
				padding: 0 30rpx;
				box-sizing: border-box;

				.item {
					border-bottom: 1px solid #EEEEEE;
					padding: 25rpx 20rpx 25rpx 0rpx;
					box-sizing: border-box;
					display: flex;

					image {
						width: 150rpx;
						height: 150rpx;
						border-radius: 10rpx;
					}

					.item_view {
						flex: 1;
						padding: 10rpx 0 5rpx 20rpx;
						box-sizing: border-box;
						overflow: hidden;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.name {
							color: #333333;
							font-size: 26rpx;
							white-space: nowrap;
							text-overflow: ellipsis;
							overflow: hidden;
						}

						.oper {
							display: flex;
							justify-content: space-between;

							.price {
								display: flex;
								align-items: flex-end;

								.unit {
									color: #F2260C;
									font-size: 26rpx;
									font-weight: bold;
								}

								.value {
									color: #F2260C;
									font-size: 36rpx;
									font-weight: bold;
								}
							}
						}
					}
				}
			}
		}

		.footer {
			height: 130rpx;
			padding: 30rpx 25rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;

			.number {
				display: flex;
				align-items: flex-end;

				.key {
					color: #999999;
					font-size: 28rpx;
					font-weight: bold;
				}

				.value {
					color: #F23031;
					font-size: 60rpx;
					font-weight: bold;
				}
			}

			.submit {
				width: 236rpx;
				height: 70rpx;
				line-height: 70rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 26rpx;
				font-weight: bold;
				border-radius: 10rpx;
				background: #CA1C1D;
			}
		}
	}
</style>